<?php

/**
 * MVM_MALL 网上商店系统  流量统计管理
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * $Author:  www.mvmmall.com  $
 * $Date: 2008-10-01 $
 * $Id: flow_stats.inc.php www.mvmmall.com$
 * ---------------------------------------------
*/

if(!defined('MVMMALL') || !defined('IN_ADMINCP')) exit('Access Denied');
if($action=='list'){
    switch ($per){
        case 'date':
            {
                $ps_day = $ps_day?date('Y-m-d',time_format($ps_day)):date('Y-m-d');
                $s_day  = dhtmlchars(eregi_replace('-','',$ps_day));
                $list   = $db->get_one("SELECT * FROM `{$tablepre}time_table` WHERE time_regdate = '$s_day' ORDER BY uid");
                $show_top = "0";
                for($i=0 ; $i<24 ; $i++) {
                    $temp_num = sprintf("%02d",$i);
                    $temp_time_hit = "time_hit_$temp_num";
                    $show_top < $list[$temp_time_hit] && $show_top = $list[$temp_time_hit];
                    $sum_hit = $sum_hit + $list[$temp_time_hit];
                }
                require_once template('flow_stats');
                footer();
                break;
            }
        case 'month':
            {
                if($ps_year && $ps_months) {
                    $ps_month  = $ps_year.sprintf("%02d",$ps_months);
                } else {
                    $ps_year   = substr($m_now_counter, 0, 4);
                    $ps_months = substr($m_now_counter, 4, 2);
                }
                if(!$ps_month) $ps_month = $m_now_month;
                $result = $db->query("SELECT * FROM {$tablepre}time_table WHERE substring(time_regdate,1,6) = $ps_month ORDER BY uid");
                $show_top = "0";
                while($list = $db->fetch_array($result)) {
                    $day_hit = 0;
                    for($i=0 ; $i<24 ; $i++) {
                        $temp_num = sprintf("%02d",$i);
                        $temp_time_hit = "time_hit_$temp_num";
                        $day_hit = $day_hit + $list[$temp_time_hit];
                    }
                    $day_temp = substr($list[time_regdate],6,2);
                    $day_sum[$day_temp] = $day_hit;
                    if($show_top < $day_hit) $show_top += $day_hit;
                    $month_sum = $month_sum + $day_hit;
                }
                $show_yy = substr($ps_month,0,4);
                $show_mm = substr($ps_month,4,2);
                $edate   = mktime(0,0,0,$show_mm,1,$show_yy);
                $show_tt = date("t",$edate);
                require_once template('flow_stats');
                footer();
                break;
            }
        default:
            {
                require_once MVMMALL_ROOT.'./include/pager.class.php';
                $counter_rt = $db->get_one("SELECT * FROM `{$tablepre}counter_table` WHERE uid = '1'");
                @extract($counter_rt,EXTR_OVERWRITE);
                $total_count = $db->counter("{$tablepre}referer_table ");
                $page        = $page ? (int)$page:1;
                $list_num    = 15;
                $rowset      = new Pager($total_count,$list_num,$page);
                $from_record = $rowset->_offset();
                $result      = $db->query("SELECT * FROM `{$tablepre}referer_table` ORDER BY referer_hit DESC LIMIT $from_record,$list_num");
                while($rt = $db->fetch_array($result)) {
                    $rt['referer'] = eregi_replace("NOT_REPERER",'利用主页地址直接输入访问',$rt['referer']);
                    $rt['rebate']  = sprintf("%01.2f",($rt['referer_hit']/$counter_total)*100);
                    $log_rt[]      = $rt;
                }
                $page_list = $rowset->link("admincp.php?module=$module&action=$action&page=");
                require_once template('flow_stats');
                footer();
            }
    }
}

//搜索关键字
elseif ($action=='search'){
    if ($setp==1&&$_POST){
        foreach ($tables_id as $val){
            $val=dhtmlchars($val);
            $db->query("DELETE FROM `{$tablepre}search_table` WHERE search_word='$val';");
        }
        hot_search(4,'update');
        admin_msg($lang[success]);
    }
    $start_date = $m_now_time-(60*60*24*30);
    $result = $db->query("SELECT COUNT(*) AS total_num,search_word FROM {$tablepre}search_table WHERE register_date > '$start_date' GROUP BY search_word ORDER BY total_num DESC LIMIT 0,50");
    require_once template('log');
}


//会员登陆记录
elseif ($action=='login'){
    $serch_sql= false;
      if(isset($ps_member)) {
            $ps_member = dhtmlchars($ps_member);
            $serch_sql = "where login_id='$ps_member'";
      }
      
      $total_count = $db->counter("{$tablepre}login_table",$serch_sql);
      require_once 'include/pager.class.php';
      $page = (int)$page;
      $list_num =  20;
      $rowset = new Pager($total_count,$list_num,$page);
      $from_record = $rowset->_offset();
      $query = "SELECT * FROM {$tablepre}login_table  $serch_sql ORDER BY uid DESC LIMIT $from_record, $list_num";
      $result = $db->query($query);
      $page_list = $rowset->link("admincp.php?module=log&action=login&page=");
      require_once template('log');
} 
//删除30条以前的数据
elseif ($action=='dellogin'){
    $temp_date = $m_now_time - (60*60*24*30);
	$db->query("DELETE FROM {$tablepre}manager_table WHERE register_date < '$temp_date'");
    admin_msg($lang[success]);
} 

elseif ($action=='cart'){
   $result = $db->query("SELECT sum(buy_number) AS total_num,goods_id,buy_number FROM {$tablepre}order_goods GROUP BY goods_id ORDER BY total_num DESC LIMIT 0,50");
   require_once template('log');
} else {
    admin_msg($lang[pass_worng]);
}
